
package org.springblade.modules.videoanswer.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.modules.videoanswer.entity.Group;
import org.springblade.modules.videoanswer.entity.Question;
import org.springblade.modules.videoanswer.entity.Video;
import org.springblade.modules.videoanswer.service.IGroupVideoService;
import org.springblade.modules.videoanswer.service.IQuestionService;
import org.springblade.modules.videoanswer.vo.VideoBaseInfoVO;
import org.springblade.modules.videoanswer.vo.VideoVO;
import org.springblade.modules.videoanswer.mapper.VideoMapper;
import org.springblade.modules.videoanswer.service.IVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

/**
 * 视频管理 服务实现类
 *
 * @author jiangyandong
 * @since 2021-03-22
 */
@Service
public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements IVideoService {

	@Autowired
	private IQuestionService questionService;
	@Autowired
	private IGroupVideoService groupVideoService;

	@Override
	public IPage<VideoVO> selectVideoPage(IPage<VideoVO> page, VideoVO video) {
		return page.setRecords(baseMapper.selectVideoPage(page, video));
	}

	@Override
	public VideoBaseInfoVO detailVideo(Video video){
		video = this.getById(video.getId());
		List<Question> questionList = questionService.list(Wrappers.<Question>query().lambda().eq(Question::getVideoId, video.getId()));
		VideoBaseInfoVO vo = new VideoBaseInfoVO();
		vo.setVideo(video);
		vo.setQuestionList(questionList);
		List<Group> groupList = groupVideoService.getGroupListByVideoid(video.getId());
		vo.setGroupList(groupList);
		return vo;
	}

}
